package com.ruoyi.project.channel.payerPayType.controller;

import java.util.List;

import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.payerPayType.domain.PayerPayType;
import com.ruoyi.project.channel.payerPayType.service.IPayerPayTypeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 支付商支付类型信息操作处理
 *
 * @author CAIN
 * @date 2019-06-29
 */
@Controller
@RequestMapping("/channel/payerPayType")
public class PayerPayTypeController extends BaseController {
    private String prefix = "channel/payerPayType";
    @Autowired
    private IUserService userService;
    @Autowired
    private IPayerPayTypeService payerPayTypeService;

    @RequiresPermissions("channel:payerPayType:view")
    @GetMapping()
    public String payerPayType() {
        return prefix + "/payerPayType";
    }

    /**
     * 查询支付商支付类型列表
     */
    @RequiresPermissions("channel:payerPayType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PayerPayType payerPayType) {
        startPage();
        List<PayerPayType> list = payerPayTypeService.selectPayerPayTypeList(payerPayType);
        return getDataTable(list);
    }


    /**
     * 导出支付商支付类型列表
     */
    @RequiresPermissions("channel:payerPayType:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PayerPayType payerPayType) {
        List<PayerPayType> list = payerPayTypeService.selectPayerPayTypeList(payerPayType);
        ExcelUtil<PayerPayType> util = new ExcelUtil<PayerPayType>(PayerPayType.class);
        return util.exportExcel(list, "payerPayType");
    }

    /**
     * 新增支付商支付类型
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        List<User> user = userService.selectPayerlList(new User());
        mmap.put("payers", user);
        return prefix + "/add";
    }

    /**
     * 新增保存支付商支付类型
     */
    @RequiresPermissions("channel:payerPayType:add")
    @Log(title = "支付商支付类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PayerPayType payerPayType) {
        return toAjax(payerPayTypeService.insertPayerPayType(payerPayType));
    }

    /**
     * 修改支付商支付类型
     */
    @GetMapping("/edit/{payTypeId}")
    public String edit(@PathVariable("payTypeId") Long payTypeId, ModelMap mmap) {
        List<User> user = userService.selectPayerlList(new User());
        mmap.put("payers", user);
        PayerPayType payerPayType = payerPayTypeService.selectPayerPayTypeById(payTypeId);
        mmap.put("payerPayType", payerPayType);
        return prefix + "/edit";
    }

    /**
     * 修改保存支付商支付类型
     */
    @RequiresPermissions("channel:payerPayType:edit")
    @Log(title = "支付商支付类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PayerPayType payerPayType) {
        return toAjax(payerPayTypeService.updatePayerPayType(payerPayType));
    }

    /**
     * 删除支付商支付类型
     */
    @RequiresPermissions("channel:payerPayType:remove")
    @Log(title = "支付商支付类型", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(payerPayTypeService.deletePayerPayTypeByIds(ids));
    }

    /**
     * 获取系统自带支付类型
     * @return
     */
    @GetMapping("/selfPayType")
    @ResponseBody
    public AjaxResult getSelfPayType(){
        PayerPayType search = new PayerPayType();
        search.setPayerUserName("系统自带");
        List<PayerPayType> payerPayTypes = payerPayTypeService.selectPayerPayTypeList(search);
        return AjaxResult.success("success",payerPayTypes);
    }
}
